package CutLoad.mc
{
	import flash.events.MouseEvent;

	/**
	 * 对多个McMouseOverLoopPlayOutStop实例，组合在一起，点其中一个，处于选重状态，其它变为初始状态
	 * @author smallerbird mail:smallerbird@gmail.com  site:www.mkigm.com QQ群:49983196
	 * 下午11:08:00
	 *
	 */	
	public class McMouseOverLoopPlayOutStop_SomeCLickOnlySelectOne
	{
		private var arr:Array;
		private var current:McMouseOverLoopPlayOutStop;
		private var changOne:Function;
		/**
		 * 初始化 
		 * @param arr 需要组合的.格式[McMouseOverLoopPlayOutStop实例1,McMouseOverLoopPlayOutStop实例2...]
		 * @param changOne 改变的状态回调方法  格式：function(index:Number,某一个McMouseOverLoopPlayOutStop实例:McMouseOverLoopPlayOutStop);
		 * @param isSelectOne 是否第一个处于选重状态
		 * 
		 */		
		public function McMouseOverLoopPlayOutStop_SomeCLickOnlySelectOne(arr:Array,changOne:Function,isSelectOne:Boolean=false)
		{
			this.arr=arr;
			this.changOne=changOne;
			current=arr[0] as McMouseOverLoopPlayOutStop;
			if(isSelectOne) current.select=true;
			for(var i:Number=0;i<arr.length;i++){
				var item:McMouseOverLoopPlayOutStop=arr[i];
				init_one(item);
			}
		}
		/**
		 * 添加一个McMouseOverLoopPlayOutStop实例,进入控制队列
		 * @param item
		 * 
		 */		
		public function add(item:McMouseOverLoopPlayOutStop):void{
			item.select=false;
			arr.push(item);
			init_one(item);
		}
		/**
		 * 设置某一个为选重状态 
		 * @param index
		 * @param isSelect
		 * 
		 */		
		public function setSelect(index:Number,isSelect:Boolean):void{
			if(index<0||index>arr.length-1) return;
			current.select=false;
			current=arr[index];
			current.select=true;
		}
		/**
		 * 清除所有对象 
		 * 
		 */		
		public function killMe():void{
			for(var i:Number=0;i<arr.length;i++){
				var item:McMouseOverLoopPlayOutStop=arr[i];
				if(item.getTarget().hasEventListener(MouseEvent.CLICK)){
					item.getTarget().removeEventListener(MouseEvent.CLICK,click);
				}
			}
			arr=new Array();
		}
		//初始某一个，的按钮点击状态
		private function init_one(item:McMouseOverLoopPlayOutStop):void{
			item.getTarget().addEventListener(MouseEvent.CLICK,click);
		}
		//点击事件
		private function click(e:MouseEvent):void{
			for(var i:Number=0;i<arr.length;i++){
				var item:McMouseOverLoopPlayOutStop=arr[i];
				if(e.target==item.getTarget()){
					current.select=false;
					current=item
					current.select=true;
					changOne(i,item);
					break;
				}
			}
			//
			//
		}
	}
}